import QtQuick 1.0
import InvMA 1.0

FocusScope {
    id: root

    property alias font: textEdit.font

    property alias cursorPosition: textEdit.cursorPosition
    property alias text: textEdit.text
    property alias readOnly: textEdit.readOnly


    function copy() {
        textEdit.copy()
    }

    function paste() {
        textEdit.paste()
    }

    function cut() {
        textEdit.cut()
    }

    function positionAt(x, y) {
        var p = mapToItem(textEdit, x, y);
        return textEdit.positionAt(p.x, p.y)
    }

    onActiveFocusChanged: {
        if (activeFocus && !readOnly) {
            textEdit.openSoftwareInputPanel();
            //repositionTimer.running = true;
        } else if (!activeFocus) {
            if (!readOnly) {
                textEdit.closeSoftwareInputPanel();
            }
        }
    }

    Rectangle {
        id: wrapperTE
        anchors.fill: parent
        color: "white"
        border.color: "blue"
        radius: 5
        //width: parent.width - 2*anchors.leftMargin
        //height: 40
        clip: true

        TextInput {
            id: textEdit
            anchors.top: parent.top;
            anchors.left: parent.left; anchors.leftMargin: 5
            width: parent.width - 2*anchors.leftMargin
            height: parent.height
            font.pixelSize: 28

            InverseMouseArea {
                anchors.fill: parent
                enabled: root.activeFocus
                onClickedOutside: {
                    root.parent.focus = true;
                }
            }
        }
    }


}
